package com.gxa.mall.controller;

import com.gxa.mall.common.CommonResult;
import com.gxa.mall.model.Admin;
import com.gxa.mall.model.Employee;
import com.gxa.mall.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 员工控制层
 */
@RestController
@ResponseBody
@RequestMapping(path = "/employee")
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;

    @RequestMapping(path ="/getList")
    //getdrugtpyeList(查询报表中药品剂型数据)
    public CommonResult  getdrugtpyeList(){
        CommonResult commonResult=null;
        try {
            List<Integer>list=new ArrayList<Integer>();
            //20-30
            Integer num1=   employeeService.getdrugtpyeList1();
            //31-60
            Integer num2=   employeeService.getdrugtpyeList2();
            //60-65
            Integer num3=   employeeService.getdrugtpyeList3();
            //未填
            Integer num4=   employeeService.getdrugtpyeList4();
            int num5=num4-num3-num2-num1;
            list.add(num1);
            list.add(num2);
            list.add(num3);
            list.add(num5);
            commonResult=new CommonResult(200,"数量查询成功",list);
            return commonResult;
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"数量查询失败",null);
        }
        return commonResult;
    }







    //tosumemday 今日新添加的
    @RequestMapping(path = "/tosumemday")
    public CommonResult  tosumemday(){
        CommonResult commonResult=null;
        try {
            Integer todayemnum=   employeeService.tosumemday();
            if (todayemnum==null){
                todayemnum=0;
            }
            commonResult=new CommonResult(200,"员工数量查询成功",todayemnum);
            return commonResult;
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"员工数量查询失败",null);
        }
        return commonResult;
    }



    /*查询员工的个数*/

    @RequestMapping(path = "/tosumem")
    public CommonResult  tosumem(){
        CommonResult commonResult=null;
        try {
           Integer emnum=   employeeService.tosumem();
            commonResult=new CommonResult(200,"员工数量查询成功",emnum);
            return commonResult;
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"员工数量查询失败",null);
        }
        return commonResult;
    }


    /**
     * 查询全体员工信息
     * @param employee
     * @return
     */
    @RequestMapping(path = "/toseekemployee")
    public CommonResult<List<Employee>> toseekemployee(Employee employee){
        CommonResult commonResult=null;
        try {
         List<Employee> list=   employeeService.toseekemployee();
            commonResult=new CommonResult(200,"员工查询成功",list);
            return commonResult;
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"员工查询失败",null);
        }
        return commonResult;
    }

    /**
     * 按结果查询员工信息
     * @param text 查询框中的内容
     * @return
     */
    @RequestMapping(path = "tolikeseek")
    public CommonResult<List<Employee>> tolikeseek(String text){
        CommonResult commonResult=null;
        try {
        List<Employee>  employees= employeeService.tolikeseek(text);
            commonResult=new CommonResult(200,"查询成功",employees);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"查询失败",null);
        }
        return commonResult;
    }

    /**
     * 修改员工
     * @param employee
     * @return
     */
    @RequestMapping(path = "/saveemployee")
    public CommonResult saveemployee(Employee employee){
        CommonResult commonResult=null;
        try {
            employeeService.saveemployee(employee);
            commonResult=new CommonResult(200,"添加成功",null);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"添加失败",null);
        }
        return commonResult;
    }



    @RequestMapping(path = "/addemployee")
    public CommonResult addemployee(Employee employee){
        CommonResult commonResult=null;
        try {
              employeeService.addemployee(employee);
                commonResult=new CommonResult(200,"添加成功",null);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"添加失败",null);
        }
        return commonResult;
    }
    /**
     * 根据id查询员工信息
     */
    @RequestMapping(path = "/toupdata")
    public CommonResult toupdata(Integer id){
        CommonResult commonResult=null;
        try {
          Employee employee=  employeeService.toupdata(id);
            commonResult=new CommonResult(200,"查询成功",employee);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"查询失败",null);
        }
        return commonResult;
    }

    /**
     * 根据id删除员工
     * @param id 要删除的员工id
     * @return
     */
    @RequestMapping(path = "/toremove")
    public CommonResult toremove(Integer id){
        CommonResult commonResult=null;
        try {
            employeeService.toremove(id);
            commonResult=new CommonResult(200,"删除成功",null);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"删除失败",null);
        }
        return commonResult;
    }

}
